home *** CD-ROM | disk | FTP | other *** search
- property pStraights, pBends, pBoxes, pBoxesPos, pStraightsReset, pBendsReset, pStraightsComplete, pBendsComplete, hk, pBall, pBallRB, pPipes, pArrow, pCup, pGap, pNormalShader, pGlowShader, pNoHks, pTime, pTimeGone, pPipeActive, pPipeTotal, pPipesUsed, pAdjSlots, pLandCount, pStuckCount, pFadeState, pLevelScore, pPipeScore, pMovesLeft, pMovesMax, pLevelFailure, leftkey, rightkey, downkey, upkey, spacekey, dcam, cam, dcamCenter, pCamZoom, pCamRotate, pRotX, pRotY, pMousePrevX, pMousePrevY, pRotations, pSucker, pLoaderData
- global w3d, gKeyOn, gGameMode, gLevel, gScore, gSkillMode, gMenuCalled, gGameType, gPuzzleSize, gClickedArrow
-
- on beginSprite me
- w3d = sprite(2).member
- w3d.resetWorld()
- hk = member(1)
- hk.Initialize(w3d, 1, 0.025)
- pStraights = []
- pBends = []
- pBoxes = []
- pBoxesPos = []
- pRotations = [vector(0, 0, 90), vector(90, 0, 0), vector(0, 0, 0), vector(0, 90, 0), vector(0, 180, 0), vector(0, 270, 0), vector(180, 0, 0), vector(180, 90, 0), vector(0, 0, 180), vector(180, 270, 0), vector(0, 270, 90), vector(90, 0, 0), vector(270, 0, 0), vector(0, 90, 90)]
- loadLevel()
- getCompleteLevels()
- setupGame()
- setupObjects(me)
- setupCamera()
- end
-
- on loadLevel
- if gGameType = "full" then
- levelMember = member("Levels")
- else
- levelMember = member("LevelsDemo")
- end if
- txt = levelMember.text.line[gLevel]
- if txt.word.count < 8 then
- alert("Error loading level")
- return
- end if
- pLoaderData = []
- pLoaderData.add(vector(float(txt.word[4]), float(txt.word[5]), float(txt.word[6])))
- pLoaderData.add(vector(float(txt.word[7]), float(txt.word[8]), float(txt.word[9])))
- pLoaderData.add(integer(txt.word[3]))
- n = 10
- lim = value(txt.word[2])
- gPuzzleSize = lim
- m = w3d.model[1]
- t = m.getWorldTransform()
- repeat with x = 1 to lim
- repeat with y = 1 to lim
- repeat with z = 1 to lim
- i = integer(txt.word[n])
- n = n + 1
- if (i > 0) and (i < 4) then
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- if i <> 1 then
- m.rotate(pRotations[i - 1])
- end if
- pStraights.add(m.transform.duplicate())
- next repeat
- end if
- if (i > 3) and (i < 16) then
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- m.rotate(pRotations[i - 1])
- pBends.add(m.transform.duplicate())
- next repeat
- end if
- if i = 16 then
- pBoxesPos.add(vector((x - 1) * 16, (y - 1) * -16, (z - 1) * -16))
- end if
- end repeat
- end repeat
- end repeat
- m.transform = t
- end
-
- on getCompleteLevels
- if gGameType = "full" then
- levelMember = member("LevelsComplete")
- else
- levelMember = member("LevelsCompleteDemo")
- end if
- txt = levelMember.text.line[gLevel]
- if txt.word.count < 8 then
- alert("Error loading complete level")
- return
- end if
- pStraightsComplete = []
- pBendsComplete = []
- n = 10
- m = w3d.model[1]
- t = m.getWorldTransform()
- repeat with x = 1 to gPuzzleSize
- repeat with y = 1 to gPuzzleSize
- repeat with z = 1 to gPuzzleSize
- i = integer(txt.word[n])
- n = n + 1
- if (i > 0) and (i < 4) then
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- if i <> 1 then
- m.rotate(pRotations[i - 1])
- end if
- pStraightsComplete.add(m.transform.duplicate())
- next repeat
- end if
- if (i > 3) and (i < 16) then
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- m.rotate(pRotations[i - 1])
- pBendsComplete.add(m.transform.duplicate())
- end if
- end repeat
- end repeat
- end repeat
- m.transform = t
- end
-
- on setupObjects me
- pGlowShader = w3d.shader("GlowGlassShader")
- pNormalShader = w3d.shader("GlassShader")
- pNormalShader.blend = 50
- pGlowShader.blend = 70
- hk.gravity = vector(0, -200, 0)
- pBall = w3d.model("Ball")
- pCup = w3d.model("Cup")
- pSucker = w3d.model("BallSucker")
- pBall.worldPosition = pLoaderData[1]
- pCup.worldPosition = pLoaderData[2]
- pSucker.transform.position = pBall.worldPosition
- if gPuzzleSize > 3 then
- w3d.model("BoxOutline").scale(1.33329999999999993, 1.33329999999999993, 1.33329999999999993)
- end if
- pPipes = []
- num = 1
- repeat with i = 1 to pStraights.count
- w3d.model("Pipe_Straight(Glass)").clone("Pipe" & num)
- m = w3d.model("Pipe" & num)
- m.transform = pStraights[i]
- pPipes.add(m)
- num = num + 1
- end repeat
- repeat with i = 1 to pBends.count
- w3d.model("Pipe_Bend(Glass)").clone("Pipe" & num)
- m = w3d.model("Pipe" & num)
- m.transform = pBends[i]
- pPipes.add(m)
- num = num + 1
- end repeat
- pPipeTotal = num - 1
- w3d.deleteModel("Pipe_Straight(Glass)")
- w3d.deleteModel("Pipe_Bend(Glass)")
- w3d.deleteModel("Glow_Bend(Glass)")
- w3d.deleteModel("Glow_Straight(Glass)")
- pPipeActive = pPipes[1]
- pPipeActive.shaderList[getShaderNum(pPipeActive)] = pGlowShader
- pBoxes = []
- repeat with i = 1 to pBoxesPos.count
- w3d.model("BoxChrome").clone("BoxChrome" & i)
- m = w3d.model("BoxChrome" & i)
- m.transform.position = pBoxesPos[i]
- pBoxes.add(m)
- end repeat
- w3d.deleteModel("BoxChrome")
- pArrow = [w3d.model("Arrow")]
- pArrow[1].scale(1.5)
- pArrow[1].pointAtOrientation = [vector(0, 1, 0), vector(1, 0, 0)]
- repeat with i = 1 to 5
- b = w3d.model("Arrow").clone("Arrow" & i)
- b.pointAtOrientation = [vector(0, 1, 0), vector(1, 0, 0)]
- pArrow.add(b)
- end repeat
- setArrows()
- bf = w3d.newTexture("BlackFade", #fromCastMember, member("black"))
- w3d.camera[1].addOverlay(bf, point(0, 0), 0)
- w3d.camera[1].overlay[1].scale = 840
- w3d.camera[1].overlay[1].blend = 100
- if not gClickedArrow then
- bf = w3d.newTexture("helpOL", #fromCastMember, member("helpOL"))
- w3d.camera[1].addOverlay(bf, point(80, 570), 0)
- w3d.camera[1].overlay[2].blend = 0
- end if
- end
-
- on setPipes setType
- if setType = "start" then
- straights = pStraights
- bends = pBends
- else
- if setType = "complete" then
- straights = pStraightsComplete
- bends = pBendsComplete
- else
- if setType = "back" then
- straights = pStraightsReset
- bends = pBendsReset
- end if
- end if
- end if
- pStraightsReset = []
- pBendsReset = []
- num = 1
- repeat with i = 1 to pStraights.count
- m = w3d.model("Pipe" & num)
- pStraightsReset[i] = m.getWorldTransform()
- m.transform = straights[i]
- num = num + 1
- end repeat
- repeat with i = 1 to pBends.count
- m = w3d.model("Pipe" & num)
- pBendsReset[i] = m.getWorldTransform()
- m.transform = bends[i]
- num = num + 1
- end repeat
- setArrows()
- end
-
- on getShaderNum pipe
- if string(pipe.resource.name).length < 20 then
- return 2
- else
- return 1
- end if
- end
-
- on makeHK
- pPipeActive.shaderList[getShaderNum(pPipeActive)] = pNormalShader
- repeat with i = 1 to 6
- pArrow[i].transform.position = vector(0, 1000, 0)
- end repeat
- pNoHks = ["Ball", "Marker"]
- pBall.addModifier(#meshDeform)
- pBallRB = hk.makeMovableRigidBody(pBall.name, 1, 1, #sphere)
- pBallRB.restitution = 0.20000000000000001
- pBallRB.friction = 0.80000000000000004
- pBallRB.linearVelocity = vector(0, 0, 0)
- pBallRB.angularVelocity = vector(0, 0, 0)
- pCup.addModifier(#meshDeform)
- rb = hk.makeFixedRigidBody(pCup.name, 0)
- rb.restitution = 0.0
- rb.friction = 0.80000000000000004
- repeat with i = 1 to pPipes.count
- pPipes[i].addModifier(#meshDeform)
- rb = hk.makeFixedRigidBody(pPipes[i].name, 0)
- rb.restitution = 0.0
- rb.friction = 0.80000000000000004
- end repeat
- pGap = []
- m = w3d.model[1]
- t = m.getWorldTransform()
- repeat with x = 1 to gPuzzleSize
- repeat with y = 1 to gPuzzleSize
- repeat with z = 1 to gPuzzleSize
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- foundPipe = 0
- repeat with p in pPipes
- dPipe = m.worldPosition.distanceTo(p.worldPosition)
- if dPipe < 5 then
- foundPipe = 1
- end if
- end repeat
- if not foundPipe then
- pGap.add(m.worldPosition)
- end if
- end repeat
- end repeat
- end repeat
- m.transform = t
- soundFX("drop", 3, 255)
- mend = member("roll").duration
- sound(2).volume = 0
- sound(2).play([#member: member("roll"), #startTime: 0, #endTime: mend, #loopStartTime: 0, #loopEndTime: mend, #loopCount: 1000])
- gGameMode = #drop
- end
-
- on setupGame
- pTime = the timer
- pAdjSlots = [vector(16, 0, 0), vector(-16, 0, 0), vector(0, 16, 0), vector(0, -16, 0), vector(0, 0, 16), vector(0, 0, -16)]
- pLandCount = 0
- pStuckCount = 0
- pLevelScore = 0
- pPipeScore = 0
- pMovesMax = pLoaderData[3]
- if gSkillMode < 3 then
- pMovesLeft = pMovesMax * 2
- else
- pMovesLeft = pMovesMax
- end if
- pPipesUsed = 0
- pFadeState = #up
- pLevelFailure = 0
- setVariable(sprite(1), "score", string(gScore))
- setVariable(sprite(1), "level", string(gLevel))
- setVariable(sprite(1), "movesLeft", string(pMovesLeft))
- moveFlash("main" & gSkillMode)
- gMenuCalled = 0
- gGameMode = #play
- end
-
- on checkTimer
- pTimeGone = the timer - pTime
- if (pTimeGone > 200) and not gClickedArrow then
- if w3d.camera[1].overlay[2].blend = 0 then
- w3d.camera[1].overlay[2].blend = 100
- end if
- end if
- ntSecs = integer(pTimeGone / 60.0)
- ntMins = integer(ntSecs / 60.0)
- ntSecs = integer(ntSecs - (ntMins * 60.0))
- if ntSecs < 0 then
- ntMins = ntMins - 1
- ntSecs = ntSecs + 60
- end if
- if ntMins < 10.0 then
- ntMins = "0" & string(ntMins)
- end if
- if ntSecs < 10.0 then
- ntSecs = "0" & string(ntSecs)
- end if
- nt = string(ntMins) & ":" & string(ntSecs)
- setVariable(sprite(1), "time", nt)
- end
-
- on enterFrame
- prevScore = pLevelScore
- if gGameMode = #dropbutton then
- makeHK()
- gGameMode = #drop
- else
- if gGameMode = #drop then
- checkDrop()
- else
- if gGameMode = #play then
- checkTimer()
- else
- if gGameMode = #reset then
- setPipes("start")
- gGameMode = #play
- else
- if gGameMode = #hint then
- setPipes("complete")
- gGameMode = #hintwait
- else
- if gGameMode = #hintwait then
- checkTimer()
- else
- if gGameMode = #hintend then
- setPipes("back")
- gGameMode = #play
- else
- if gGameMode = #finish then
- if pFadeState <> #down then
- pFadeState = #down
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- updateCamera()
- if pLevelScore <> prevScore then
- setVariable(sprite(1), "levelScore", string(pLevelScore))
- end if
- if pFadeState <> #none then
- fadeLevel()
- end if
- end
-
- on checkDrop
- pos = pBall.worldPosition
- vel = pBallRB.linearVelocity.magnitude
- sound(2).volume = vel
- if vel < 5 then
- pStuckCount = pStuckCount + 1
- else
- pStuckCount = 0
- end if
- repeat with p in pPipes
- dPipe = pos.distanceTo(p.worldPosition)
- ps = p.shaderList[getShaderNum(p)].name
- if (dPipe < 10) and (ps = "GlassShader") then
- soundFX("light", 3, 100)
- pPipesUsed = pPipesUsed + 1
- p.shaderList[getShaderNum(p)] = pGlowShader
- end if
- end repeat
- if gSkillMode > 1 then
- repeat with p in pGap
- dGap = pos.distanceTo(p)
- if dGap < 10 then
- pLevelFailure = 1
- end if
- end repeat
- end if
- dCup = pos.distanceTo(pCup.worldPosition)
- if dCup < 12 then
- pLandCount = pLandCount + 1
- end if
- if (pLandCount > 0) and (pLandCount < 50) then
- dy = pos.y - pCup.worldPosition.y
- if dy < 0 then
- soundFX("land", 3, 100)
- sound(2).stop()
- pLandCount = 50
- end if
- end if
- if pLandCount > 70 then
- gGameMode = #finish
- end if
- dy = pCup.worldPosition.y - pos.y
- if dy > 0 then
- sound(2).volume = 0
- end if
- if (dy > 500) or (pStuckCount > 100) then
- pLevelFailure = 1
- gGameMode = #finish
- end if
- end
-
- on setArrows
- repeat with i = 1 to 6
- pArrow[i].transform.position = vector(0, 1000, 0)
- end repeat
- arrowNum = 1
- p = pPipeActive.worldPosition
- if gPuzzleSize = 3 then
- upperLimit = 33
- else
- if gPuzzleSize = 4 then
- upperLimit = 49
- end if
- end if
- repeat with i in pAdjSlots
- pos = p + i
- if (pos.x < upperLimit) and (pos.x > -1) and (pos.y < 1) and (pos.y > -upperLimit) and (pos.z < 1) and (pos.z > -upperLimit) then
- blocked = 0
- repeat with b in pPipes
- d = (pos - b.worldPosition).magnitude
- if d < 1 then
- blocked = 1
- end if
- end repeat
- repeat with b in pBoxes
- d = (pos - b.worldPosition).magnitude
- if d < 1 then
- blocked = 1
- end if
- end repeat
- if not blocked then
- pArrow[arrowNum].transform.position = pos
- pArrow[arrowNum].translate(0.01, 0.01, 0.01)
- pArrow[arrowNum].pointAt(p + (i * 2), vector(0, 1, 0))
- pArrow[arrowNum].transform.position = pos
- arrowNum = arrowNum + 1
- end if
- end if
- end repeat
- end
-
- on fadeLevel
- f = cam.overlay[1].blend
- if pFadeState = #up then
- if f > 0 then
- cam.overlay[1].blend = f - 5
- else
- cam.overlay[1].blend = 0
- pFadeState = #none
- end if
- else
- if pFadeState = #down then
- if f < 100 then
- cam.overlay[1].blend = f + 5
- else
- cam.overlay[1].blend = 100
- pFadeState = #none
- endOfLevel()
- end if
- end if
- end if
- end
-
- on endOfLevel
- pipesScore = integer(pPipesUsed / float(pPipeTotal) * 100)
- if (gSkillMode = 3) or (pMovesLeft >= pMovesMax) then
- movesScore = 100
- else
- movesScore = integer(pMovesLeft / float(pMovesMax) * 100)
- end if
- maxSecs = pMovesMax * 6
- secs = integer(pTimeGone / 60.0)
- if secs < maxSecs then
- timeScore = 100
- else
- timeScore = integer(((maxSecs * 2) - secs) / float(maxSecs) * 100)
- end if
- if timeScore < 0 then
- timeScore = 0
- end if
- if gMenuCalled or ((gSkillMode > 1) and (pipesScore < 100)) then
- pLevelFailure = 1
- end if
- if pLevelFailure then
- if not gMenuCalled then
- gLevel = gLevel - 1
- end if
- pipesScore = 0
- movesScore = 0
- timeScore = 0
- levelScore = 0
- setVariable(sprite(1), "levelButtTxt", "REPLAY LEVEL")
- else
- setVariable(sprite(1), "levelButtTxt", "NEXT LEVEL")
- levelScore = integer((pipesScore + movesScore + timeScore) / 3.0)
- end if
- gScore = gScore + levelScore
- setVariable(sprite(1), "movesScore", string(movesScore))
- setVariable(sprite(1), "timeScore", string(timeScore))
- setVariable(sprite(1), "pipeScore", string(pipesScore))
- setVariable(sprite(1), "levelScore", string(levelScore))
- setVariable(sprite(1), "score", string(gScore))
- repeat with i = 1 to 8
- sound(i).stop()
- end repeat
- go(the frame + 1)
- end
-
- on setupCamera
- cam = w3d.camera[1]
- cam.fieldOfView = 50
- dcam = w3d.newModel("dummyCam")
- dcamCenter = w3d.newModel("dummyCenter")
- if gPuzzleSize = 3 then
- dcamCenter.transform.position = vector(16, -16, -16)
- pCamZoom = 60
- else
- if gPuzzleSize = 4 then
- dcamCenter.transform.position = vector(24, -24, -24)
- pCamZoom = 80
- end if
- end if
- dcamCenter.addChild(dcam, #preserveParent)
- dcam.translate(-pCamZoom, 0, -pCamZoom)
- pRotX = 0
- pRotY = 0
- end
-
- on mouseDown me
- clickItem = 0
- if gGameMode = #play then
- m = cam.modelsUnderLoc(the mouseLoc, 3, #simple)
- if m.count > 0 then
- repeat with i = 1 to m.count
- if chars(m[i].name, 1, 5) = "Arrow" then
- pPipeActive.worldPosition = m[i].worldPosition
- pMovesLeft = pMovesLeft - 1
- if pMovesLeft < 0 then
- pMovesLeft = 0
- end if
- if gSkillMode > 1 then
- if pMovesLeft = 0 then
- gGameMode = #dropbutton
- end if
- setVariable(sprite(1), "movesLeft", string(pMovesLeft))
- end if
- setArrows()
- soundFX("click", 3, 50)
- clickItem = 1
- if not gClickedArrow then
- if w3d.camera[1].overlay[2].blend > 0 then
- w3d.camera[1].overlay[2].blend = 0
- end if
- gClickedArrow = 1
- end if
- exit repeat
- next repeat
- end if
- if chars(m[i].name, 1, 4) = "Pipe" then
- pPipeActive.shaderList[getShaderNum(pPipeActive)] = pNormalShader
- pPipeActive = m[i]
- pPipeActive.shaderList[getShaderNum(pPipeActive)] = pGlowShader
- setArrows()
- clickItem = 1
- soundFX("choose", 3, 100)
- exit repeat
- end if
- end repeat
- end if
- end if
- if not clickItem then
- pCamRotate = 1
- pMousePrevX = (the mouseLoc).locH
- pMousePrevY = (the mouseLoc).locV
- end if
- end
-
- on mouseWithin me
- if pCamRotate then
- pRotX = (the mouseLoc).locH - pMousePrevX
- pRotY = (the mouseLoc).locV - pMousePrevY
- pMousePrevX = (the mouseLoc).locH
- pMousePrevY = (the mouseLoc).locV
- end if
- if pRotX > 10 then
- pRotX = 10
- else
- if pRotX < -10 then
- pRotX = -10
- end if
- end if
- if pRotY > 10 then
- pRotY = 10
- else
- if pRotY < -10 then
- pRotY = -10
- end if
- end if
- end
-
- on mouseLeave me
- mouseUp(me)
- end
-
- on mouseUp me
- pCamRotate = 0
- end
-
- on updateCamera
- checkkeys()
- dcam.transform.position.z = pCamZoom
- dcam.transform.position.x = pCamZoom
- if upkey then
- else
- if downkey then
- end if
- end if
- if pCamRotate then
- dcamCenter.rotate(0, -pRotX, 0)
- dcam.rotate(dcamCenter.worldPosition, vector(0, 0, 1), -pRotY * 2, #self)
- end if
- if abs(dcam.worldPosition.y + 16) > 85 then
- dcam.rotate(dcamCenter.worldPosition, vector(0, 0, 1), pRotY * 2.20000000000000018, #self)
- end if
- dcam.pointAt(dcamCenter.worldPosition, vector(0, 1, 0))
- camBuffer = 20
- cam.transform.interpolateTo(dcam.getWorldTransform(), camBuffer)
- end
-
- on checkkeys
- leftkey = 0
- rightkey = 0
- downkey = 0
- upkey = 0
- spacekey = 0
- if keyPressed(123) then
- leftkey = 1
- end if
- if keyPressed(124) then
- rightkey = 1
- end if
- if keyPressed(125) then
- downkey = 1
- end if
- if keyPressed(126) then
- upkey = 1
- end if
- if keyPressed(" ") then
- spacekey = 1
- end if
- end
-
- on endSprite me
- hk.shutDown()
- w3d.resetWorld()
- end
-